<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>编辑模板</title>
  <meta name="renderer" content="webkit">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
  <link rel="stylesheet" href="__PUBLIC__/layui/css/layui.css" media="all">
  <link rel="stylesheet" href="__PUBLIC__/style/admin.css" media="all">
</head>
<body>  
  <div class="layui-fluid">
    <div class="layui-row layui-col-space15">
      <div class="layui-col-md12">
        <div class="layui-card">
          <div class="layui-card-body">
            <div class="layui-form">
              <input type="text" name="id" value="{$template.id}" hidden>
              <div class="layui-form-item">
                <label class="layui-form-label">模板名称</label>
                <div class="layui-input-block">
                  <input type="text" name="name" autocomplete="off" placeholder="请输入模板名称" lay-verify="required" class="layui-input" value="{$template.name}">
                </div>
              </div>
              <div class="layui-form-item">
                <label class="layui-form-label">模板描述</label>
                <div class="layui-input-block">
                  <textarea name="desc" placeholder="请输入模板描述" class="layui-textarea">{$template.desc}</textarea>
                </div>
              </div>
              <div class="layui-form-item">
                <label class="layui-form-label">模板代码</label>
                <div class="layui-input-block">
                  <textarea name="script" placeholder="模板代码，特殊变量请参照编写规范" style="height: 340px;" class="layui-textarea">{$template.script}</textarea>
                </div>
              </div>
              <div class="layui-form-item">
                <label class="layui-form-label"></label>
                <div class="layui-input-block">
                  <button class="layui-btn" lay-submit lay-filter="edit-submit">修改</button>
                </div>
              </div>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
  
  <script src="__PUBLIC__/layui/layui.js"></script>
  <script>
  layui.config({
    base: '__PUBLIC__/' //静态资源所在路径
  }).extend({
    index: 'lib/index' //主入口载荷
  }).use(['index', 'form'], function(){
    var form = layui.form, $ = layui.$;

    form.on('submit(edit-submit)', function(obj){
      $.post("{:U('Ajax/ajax_template_update')}" , JSON.stringify(obj.field) ,function(d){
        if(d.code == 0){
          layer.msg(d.msg, {
            icon: 1,
            time: 1000
            }, function(){
              window.parent.refreshTable();
              window.parent.layer.closeAll();
          });
        }else{
          layer.msg(d.msg);
        }
      },"json");
    });
  });
  </script>
</body>
</html>